package com.shelpe.services.sustainer.client;

import java.util.ArrayList;
import java.util.List;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.shelpe.services.sustainer.client.RankingClient.RankingClientFallback;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@FeignClient(name="${feign.algorithmserver.name}", url="${feign.algorithmserver.url}", fallback = RankingClientFallback.class)
public interface RankingClient {

	@RequestMapping(path = "/algorithmservice/rankings/{ranking_id}/@execute", method = RequestMethod.GET,  consumes="application/json;charset=UTF-8")
	RankingRes executeRanking(@PathVariable("ranking_id") long rankingID);
	
	@Data
	public static class RankingRes{
		private boolean status;
		private List<RankingResult> results;
		public void add(RankingResult res){
			if(this.results == null){
				this.results = new ArrayList<RankingResult>();
			}
			this.results.add(res);
		}
	}
	
	@Data
	public static class RankingResult{
		@JsonProperty("keyword_id")
		private long keywordID;
		private boolean result;
	}
	
	
	@RequestMapping(path = "/algorithmservice/developments/{plan_id}/@execute", method = RequestMethod.GET,  consumes="application/json;charset=UTF-8")
	DevelopmentExecutionRes executeDevelopment(@PathVariable("plan_id") long planID);
	
	@Data
	public static class DevelopmentExecutionRes{
		private boolean success;
		private long planID;
	}
	
	@Service
	@Slf4j
	public static class RankingClientFallback implements RankingClient{

		@Override
		public RankingRes executeRanking(long rankingID) {
			log.error("executeRanking: {}", rankingID);
			return new RankingRes();
		}

		@Override
		public DevelopmentExecutionRes executeDevelopment(long planID) {
			log.error("executeQscore: {}", planID);
			return new DevelopmentExecutionRes();
		}
		
	}
}